<template>
    <div id="article-content">
            <!-- 文章描述 -->
        <g-admin></g-admin>
        <el-form ref="form" :model="content">
            <el-form-item label="发布人:">
                <el-col :span="6">
                    <el-input v-model="adminName"></el-input>
                </el-col>
            </el-form-item>
            <el-form-item label="发布标题:">
                <el-col :span="6">
                    <el-input v-model="content.title"></el-input>
                </el-col>
            </el-form-item>
            <el-form-item label="点赞量:(默认为0）">
                <el-col :span="6">
                    <el-input v-model="content.goodNum"></el-input>
                </el-col>
            </el-form-item>
            <el-form-item>
                <mavon-editor v-model="content.content" @change="handle"></mavon-editor>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" size="small" @click="submit">发布</el-button>
            </el-form-item>
        </el-form>



    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: "article-content",
        created(){
            this.articleID = this.$route.query.articleID;
            this.requestForMessage(this.articleID);
        },
        data(){
            return{
                articleID:'',
                content:'',
                codeStyle:'gruvbox-light',
                adminName:'',
            }
        },
        mounted(){
            document.querySelector('.tabbar').setAttribute('style','display:none');
            document.querySelector('.gfooter').setAttribute('style','display:none');
        },
        methods:{
            requestForMessage(articleID){
                //获取文章内容
                this.request({
                    url:'/articleContent/findar/'+articleID
                }).then(res=>{
                    this.content = res.data;
                    this.adminName = res.data['adminName'];
                }).catch(err=>{
                    console.log(err);
                });
            },
            handle(value, render) {
                this.myhtml = render;
                console.log(value, render);
            },
            submit() {
                let url='http://localhost:8080/article/add';
                axios.post(url,this.form).then(
                    res=>{
                        alert("添加成功！");
                        location.reload(true);
                        console.log(res.data);
                    }
                ).catch(err=> {
                    console.log(err);
                })


            }
        }
    }
</script>

<style scoped>
    #article-content{
        margin-left: 130px;
        margin-top: 20px;
    }

</style>